define([
    'jquery',
], function($) {
    'use strict';
    $(window).on('hashchange', doChange);

    function doChange(){
        var hash = location.hash.indexOf('#') === 0 ? location.hash : '#';
        hash = parseHash(hash);
        require([hash], function(App){
            App.run();
        });
    }

    /**
     * 提取 #hash 格式中的 hash
     * 兼容 #hash?v=111 的格式
     */
    function parseHash(hashUrl){
        var hash = "";
        try{
            hashUrl = hashUrl.replace(/\#/g, "");
            var arr = hashUrl.split("?");
            hash = arr[0];
        }catch(e){
            hash = undefined;
        }
        //Todo: 添加响应的 hash
        switch(hash){
            case "list":
                hash = "list";
                break; 
            case "detail":
                hash = "detail";
                break; 
            default:
                // console.log("unknown hash:", hash, "query", query);
                hash = "main";
                break;
        }

        return hash;

    }

    return {
        doChange: doChange
    }

});